package com.cjy.drools.points.entity;

import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;

import java.util.ArrayList;
import java.util.List;

/**
 * @author cjy
 * @create 2020-03-30
 */
public class DroolMain {
    public static void main(String[] args) {
        KieServices ks = KieServices.Factory.get();
        KieContainer kc = ks.getKieClasspathContainer();
        List<Order> result = excute(kc);
        printResult(result);

    }

    private static void printResult(List<Order> results) {
        for (Order order : results) {
            System.out.println(order);
        }
    }

    private static List<Order> excute(KieContainer kc) {
        KieSession kieSession = kc.newKieSession("myAgeSession");
        List<Order> orderList = getOrders();
        for (int i = 0; i < orderList.size(); i++) {
            Order o = orderList.get(i);
            kieSession.insert(o);
            int count=kieSession.fireAllRules();
            System.out.println("执行规则："+count);

        }
        return orderList;
    }

    private static List<Order> getOrders() {
        List<Order> orderList = new ArrayList<Order>();
        orderList.add(new Order("xxx00001", 1200));
        orderList.add(new Order("xxx00002", 200));
        orderList.add(new Order("xxx00003", 99));
        orderList.add(new Order("xxx00004", 499));
        orderList.add(new Order("xxx00005", 999));  // 设置参数 drl文件里的优先级高
        return orderList;
    }
}
